# /usr/bin/python
# -*- coding: utf-8 -*-

import os,sys
BASE_DIR = os.path.dirname(os.path.abspath(os.curdir))
sys.path.append(BASE_DIR)
import re
from models.MySQL import MySQL
from models.Zabbix import ZBX
from conf.setting import templates,key_dict,func_dict
from util.log import get_stream_logger
from util.key_translate import key_trn

Z = ZBX()
templates = Z.get_template(host="")

for template in templates:
    with MySQL() as cur:
        cmd = "SELECT id FROM tpl WHERE tpl_name='%s'"%template['name']
        res = cur.search(cmd)
        if len(res) == 0:
            continue
            
        templateid = cur.search(cmd)[0][0]

        rollback = "DELETE FROM strategy WHERE tpl_id='{tpl_id}'".format(tpl_id=templateid)
        cur.update(rollback)

